<?php
/**
 * --------------------------------------------------------------
 * 广告验证器
 * --------------------------------------------------------------
 * Light Year Doc
 * @author yinq<3331653644@qq.com>
 * --------------------------------------------------------------
 */
namespace app\admin\validate;

use think\Validate;

class Advert extends Validate
{
    // 定义验证规则
    protected $rule = [
        'name|广告位标识'  => 'require|regex:^[a-z]+[a-z0-9_]{0,20}$',
        'title|广告位名称' => 'require|unique:advert',
        'start_time'      => 'requireIf:timeset,1',
        'end_time'        => 'requireIf:timeset,1',
        'ad_text'         => 'requireIf:type,1',
        'code'            => 'requireIf:type,0',
        'width'           => 'integer',
        'height'          => 'integer',
        'one_pic'         => 'requireIf:type,2',
    ];

    // 定义验证提示
    protected $message = [
        'name.regex' => '广告位标识由小写字母、数字或下划线组成，不能以数字开头',
        'code'       => '代码不能为空',
        'one_pic'    => '请上传图片',
        'ad_text'    => '文字内容不能为空',
        'start_time' => '开始时间不能为空',
        'end_time'   => '结束时间不能为空',
        'width'      => '宽度只能填写数字',
        'height'     => '高度只能填写数字',
    ];
}